;;;;;;;;;;
;;
;; Use IDO mode!
;;
;; http://www.emacswiki.org/emacs/InteractivelyDoThings helps to get started
;;



;;;;;;;
;; Dired mode powered by ido mode
(defcustom my-dired-aliases
  '(("evo" . "/Users/markus/Dev/ttevo")
    ("python" . "/Users/markus/Dev/python"))
  "A list of special directoy aliases. List is used by function
`my-ido-dired' to make an association between an alias and the
logical path."
  :type '(repeat (cons (string :tag "Alias")
                       (string :tag "Path")))
  :group 'my-customs)


(defun my-ido-dired (&optional alias)
  (interactive)
  (let ((dired-aliases (mapcar (lambda (e) (car e)) my-dired-aliases)))
    (unless alias
      (setq alias
            (ido-completing-read "Alias: "
                                 dired-aliases
                                 nil t)))
    (if (and (stringp alias) (> (length alias) 0 ))
        (let ((pair (assoc alias my-dired-aliases)))
          (if pair
              (dired (cdr pair))
            (error "Invalid alias %s" alias)))
      (error "Invalid alias %s" alias))))


;; Navigate with dired to your root directory of the working tree and use this
;; key binding.
(add-hook 'dired-mode-hook
          (lambda ()
            (local-set-key (kbd "C-c c") 'desktop-change-dir)))


(defun my-ido-find-file-in-tag-files ()
  "An ido-method to open a file, that is listed in the visited
tags file. Customize `ido-case-fold' to select the right input
method that works for you."
  (interactive)
  (save-excursion
    (let ((enable-recursive-minibuffers t))
      (visit-tags-table-buffer))
    (find-file
     (expand-file-name
      (ido-completing-read
       "Open file: " (tags-table-files) nil t)))))


(defun my-ido-read-tag (prompt &optional require-match initial-input)
  "Return the name of a tag in the current tags table."
  (let ((enable-recursive-minibuffers t))
    (visit-tags-table-buffer))
  (ido-completing-read prompt
                       (let ((accum (list)))
                         (mapatoms (lambda (arg) (push (symbol-name arg) accum))
                                   (tags-completion-table))
                         accum)
                       nil
                       require-match
                       initial-input))



(defun my-ido-find-tag (prefix)
  "Without prefix, go to the selected tag. With prefix, insert
the selected tag at point."
  (interactive "P")
  (let ((buf (car buffer-name-history)) ;; remember where to insert the tag
        (tag (my-ido-read-tag "Find tag: " nil ""))) ;; choose the tag
    (if prefix
        (progn (switch-to-buffer buf)
               (insert tag))
      (find-tag tag))))

(provide 'resource/ido.el)
